@using BlazorApp.Utils.Prometheus.Models.Interfaces
@inherits BlazorApp.Pages.Common.PageBase

@if (AllMetrics is { Count: > 0 })
{
    if (AllMetrics.Any(x => x.Name == MetricName))
    {
        <GridRow Class="grid-table">
            <GridCol Span="16">@Title</GridCol>
            <GridCol Span="8">
                @{ var result = AllMetrics
                       .FirstOrDefault(x => x.Name == MetricName)?
                       .Measurements
                       .Where(x => x.Name == $"{MetricName}_{CalcField}")
                       .Sum(x => x.Value); }
                <NumberFormat Number="@result" Unit="@Unit"></NumberFormat>
                @if (OnDetailClick.HasDelegate)
                {
                    <Button Type="@ButtonType.Link" OnClick="@OnDetailClick">@L["Detail"]</Button>
                }
            </GridCol>
        </GridRow>
    }
}

@code {

    [Parameter] public IList<IMetric> AllMetrics { get; set; }

    [Parameter] public string MetricName { get; set; }

    [Parameter] public string Title { get; set; }

    [Parameter] public string CalcField { get; set; }

    [Parameter] public string Unit { get; set; }

    [Parameter] public EventCallback OnDetailClick { get; set; }

}
